package com.itheima.dbsharding.simple.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Created by Administrator.
 */

@Mapper
@Component
public interface DictDao {

    /**
     * 新增字典
     * @param type 字典类型
     * @param code 字典编码
     * @param value 字典值
     * @return
     */
    @Insert("insert into t_dict(dict_id,type,code,value) value(#{dictId},#{type},#{code},#{value})")
    int insertDict(@Param("dictId") Long dictId, @Param("type") String type, @Param("code")String code, @Param("value")String value);

    /**
     * 删除字典
     * @param dictId 字典id
     * @return
     */
    @Delete("delete from t_dict where dict_id = #{dictId}")
    int deleteDict(@Param("dictId") Long dictId);


    /**
     * 关联查询
     */
    @Select({"<script>" ,
            "select",
            " * ",
            " from t_user u,t_dict d " ,
            " where u.user_type = d.code ",
            "AND u.user_id in " ,
            " <foreach collection='userIds' open='(' separator=',' close=')' item='id'>" +
            " #{id} " ,
            " </foreach>" ,
            "</script>"
    })
    List<Map> selectUserInfoByIds(@Param("userIds") List<Long> userIds);

}
